package com.kanavi.dataAccess.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisPlusInterceptorConfiguration {

  @Autowired private ApiAuthInterceptor apiAuthInterceptor;

  @Bean
  public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptors = new MybatisPlusInterceptor();
    interceptors.addInnerInterceptor(apiAuthInterceptor);
    interceptors.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    return interceptors;
  }

  @Bean
  public ConfigurationCustomizer configurationCustomizer() {
    return configuration -> configuration.setMapUnderscoreToCamelCase(true);
  }
}
